﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TheSchedulator.Forms;
using CoursePack;

namespace TheSchedulator.Forms
{
    public partial class frmMain : Form
    {
        #region Data
        private Student m_Student;
        private Form m_CurrentAttachedForm;
        #endregion

        public frmMain(Student _Student)
        {
            InitializeComponent();
            this.m_Student = _Student;
            this.m_CurrentAttachedForm = new Form();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.lblSchedulator_Click(null, null);
        }

        private void lblSchedulator_Click(object sender, EventArgs e)
        {
            if (this.m_CurrentAttachedForm.Name != "Schedulator")
            {
                this.splitLevel2.Panel2.Controls.Clear();
                m_CurrentAttachedForm = new frmSchedulator(this.m_Student);
                m_CurrentAttachedForm.Name = "Schedulator";
                m_CurrentAttachedForm.ShowInTaskbar = false;
                m_CurrentAttachedForm.TopLevel = false;
                m_CurrentAttachedForm.FormBorderStyle = FormBorderStyle.None;
                m_CurrentAttachedForm.Dock = DockStyle.Fill;
                m_CurrentAttachedForm.AutoScroll = true;
                m_CurrentAttachedForm.Show();
                this.splitLevel2.Panel2.Controls.Add(m_CurrentAttachedForm);
            }
        }

        private void lblLogout_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == MessageBox.Show("Are you sure you want to logout ? All unsaved schedules will be lost.", "Logout Confirmation", MessageBoxButtons.OKCancel))
            {
                MySQLApi.SaveStudent(this.m_Student);
                this.Close();
            }
        }

        private void lblStudentAccount_Click(object sender, EventArgs e)
        {
            if (this.m_CurrentAttachedForm.Name != "MyAccount")
            {
                this.splitLevel2.Panel2.Controls.Clear();
                m_CurrentAttachedForm = new frmMyAccount(this.m_Student);
                m_CurrentAttachedForm.Name = "MyAccount";
                m_CurrentAttachedForm.ShowInTaskbar = false;
                m_CurrentAttachedForm.TopLevel = false;
                m_CurrentAttachedForm.FormBorderStyle = FormBorderStyle.None;
                m_CurrentAttachedForm.Dock = DockStyle.Fill;
                m_CurrentAttachedForm.AutoScroll = true;
                m_CurrentAttachedForm.Show();
                this.splitLevel2.Panel2.Controls.Add(m_CurrentAttachedForm);
            }
        }

        private void lblSchedulator_MouseHover_1(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(Label))
            {
                ((Label)sender).ForeColor = Color.Gray;
            }
        }

        private void lblLogout_MouseLeave(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(Label))
            {
                ((Label)sender).ForeColor = System.Drawing.SystemColors.ButtonFace;
            }
        }


    }
}
